load("//bzl:cpp_library.bzl", "cpp_library")

package(default_visibility = ["//visibility:public"])

cpp_library(
    name = "asymmetric_thread_fence",
    srcs = ["AsymmetricThreadFence.cpp"],
    hdrs = ["AsymmetricThreadFence.h"],
    deps = [
        ":relaxed_atomic",
        "//folly:exception",
        "//folly:indestructible",
        "//folly/portability:asm",
        "//folly/portability:sys_membarrier",
        "//folly/portability:sys_mman",
    ],
)

cpp_library(
    name = "atomic_ref",
    hdrs = ["AtomicRef.h"],
    deps = [
        "//folly:traits",
        "//folly/lang:safe_assert",
    ],
)

cpp_library(
    name = "atomic_util",
    hdrs = [
        "AtomicUtil.h",
    ],
    textual_hdrs = [
        "AtomicUtil-inl.h",
    ],
    deps = [
        "//folly:constexpr_math",
        "//folly:likely",
        "//folly:portability",
        "//folly:traits",
    ],
)

cpp_library(
    name = "atomic_notification",
    srcs = [
        "AtomicNotification.cpp",
    ],
    hdrs = [
        "AtomicNotification.h",
    ],
    textual_hdrs = [
        "AtomicNotification-inl.h",
    ],
    deps = [
        ":parking_lot",
        "//folly:portability",
        "//folly/detail:futex",
    ],
)

cpp_library(
    name = "atomic_struct",
    hdrs = ["AtomicStruct.h"],
    deps = [
        "//folly:constexpr_math",
        "//folly:traits",
        "//folly/synchronization/detail:atomic_utils",
    ],
)

cpp_library(
    name = "baton",
    hdrs = ["Baton.h"],
    deps = [
        ":atomic_util",
        ":wait_options",
        "//folly:likely",
        "//folly/detail:async_trace",
        "//folly/detail:futex",
        "//folly/detail:memory_idler",
        "//folly/portability:asm",
        "//folly/synchronization/detail:spin",
    ],
)

cpp_library(
    name = "call_once",
    hdrs = ["CallOnce.h"],
    deps = [
        "//folly:likely",
        "//folly:micro_lock",
        "//folly:portability",
        "//folly:shared_mutex",
        "//folly/functional:invoke",
    ],
)

cpp_library(
    name = "distributed_mutex",
    srcs = [
        "DistributedMutex.cpp",
    ],
    hdrs = [
        "DistributedMutex.h",
    ],
    textual_hdrs = [
        "DistributedMutex-inl.h",
    ],
    deps = [
        ":atomic_notification",
        ":atomic_util",
        ":lock",
        "//folly:constexpr_math",
        "//folly:function",
        "//folly:likely",
        "//folly:optional",
        "//folly:portability",
        "//folly:scope_guard",
        "//folly:utility",
        "//folly/chrono:hardware",
        "//folly/detail:futex",
        "//folly/functional:invoke",
        "//folly/lang:align",
        "//folly/lang:bits",
        "//folly/lang:exception",
        "//folly/portability:asm",
        "//folly/synchronization/detail:inline_function_ref",
        "//folly/synchronization/detail:sleeper",
        "@glog",
    ],
)

cpp_library(
    name = "hazptr",
    srcs = [
        "Hazptr.cpp",
        "HazptrDomain.cpp",
    ],
    hdrs = [
        "Hazptr.h",
        "Hazptr-fwd.h",
        "HazptrDomain.h",
        "HazptrHolder.h",
        "HazptrObj.h",
        "HazptrObjLinked.h",
        "HazptrRec.h",
        "HazptrThrLocal.h",
    ],
    deps = [
        ":asymmetric_thread_fence",
        "//folly:c_portability",
        "//folly:executor",
        "//folly:indestructible",
        "//folly:memory",
        "//folly:portability",
        "//folly:scope_guard",
        "//folly:singleton_thread_local",
        "//folly:traits",
        "//folly/concurrency:cache_locality",
        "//folly/container:f14_hash",
        "//folly/executors:inline_executor",
        "//folly/portability:config",
        "//folly/portability:gflags",
        "//folly/synchronization/detail:hazptr_utils",
        "@glog",
    ],
)

cpp_library(
    name = "hazptr_thread_pool_executor",
    srcs = ["HazptrThreadPoolExecutor.cpp"],
    hdrs = [
        "HazptrThreadPoolExecutor.h",
    ],
    deps = [
        ":hazptr",
        "//folly:singleton",
        "//folly/executors:cpu_thread_pool_executor",
    ],
)

cpp_library(
    name = "latch",
    hdrs = ["Latch.h"],
    deps = [
        ":saturating_semaphore",
        "//folly:c_portability",
        "//folly:likely",
        "//folly/lang:exception",
    ],
)

cpp_library(
    name = "lifo_sem",
    hdrs = ["LifoSem.h"],
    deps = [
        ":atomic_struct",
        ":saturating_semaphore",
        "//folly:c_portability",
        "//folly:indexed_mem_pool",
        "//folly:likely",
        "//folly:portability",
        "//folly:traits",
        "//folly/detail:static_singleton_manager",
        "//folly/lang:aligned",
        "//folly/lang:safe_assert",
    ],
)

cpp_library(
    name = "lock",
    hdrs = ["Lock.h"],
    deps = [
        "//folly:portability",
        "//folly:traits",
        "//folly/functional:invoke",
        "//folly/lang:exception",
        "//folly/lang:hint",
    ],
)

cpp_library(
    name = "micro_spin_lock",
    hdrs = ["MicroSpinLock.h"],
    deps = [
        ":sanitize_thread",
        "//folly:portability",
        "//folly/lang:align",
        "//folly/synchronization/detail:sleeper",
    ],
)

cpp_library(
    name = "native_semaphore",
    hdrs = ["NativeSemaphore.h"],
    deps = [
        "//folly:utility",
        "//folly/lang:exception",
        "//folly/portability:windows",
    ],
)

cpp_library(
    name = "pico_spin_lock",
    hdrs = ["PicoSpinLock.h"],
    deps = [
        ":atomic_ref",
        ":atomic_util",
        ":sanitize_thread",
        "//folly:portability",
        "//folly/lang:safe_assert",
        "//folly/synchronization/detail:sleeper",
    ],
)

cpp_library(
    name = "parking_lot",
    srcs = [
        "ParkingLot.cpp",
    ],
    hdrs = ["ParkingLot.h"],
    deps = [
        "//folly:hash",
        "//folly:indestructible",
        "//folly:portability",
        "//folly:unit",
        "//folly/lang:safe_assert",
    ],
)

cpp_library(
    name = "rcu",
    srcs = [
        "Rcu.cpp",
    ],
    hdrs = [
        "Rcu.h",
    ],
    deps = [
        "//folly:function",
        "//folly:indestructible",
        "//folly:optional",
        "//folly/detail:static_singleton_manager",
        "//folly/detail:turn_sequencer",
        "//folly/executors:queued_immediate_executor",
        "//folly/synchronization/detail:rcu-detail",
    ],
)

cpp_library(
    name = "rw_spin_lock",
    hdrs = ["RWSpinLock.h"],
    deps = [
        ":lock",
        "//folly:likely",
        "//folly:portability",
        "//folly/portability:asm",
    ],
)

cpp_library(
    name = "relaxed_atomic",
    hdrs = ["RelaxedAtomic.h"],
)

cpp_library(
    name = "sanitize_thread",
    srcs = [
        "SanitizeThread.cpp",
    ],
    hdrs = ["SanitizeThread.h"],
    deps = [
        "//folly:portability",
        "//folly/lang:extern",
    ],
)

cpp_library(
    name = "saturating_semaphore",
    hdrs = ["SaturatingSemaphore.h"],
    deps = [
        ":atomic_util",
        ":wait_options",
        "//folly:likely",
        "//folly/detail:futex",
        "//folly/detail:memory_idler",
        "//folly/portability:asm",
        "//folly/synchronization/detail:spin",
        "@glog",
    ],
)

cpp_library(
    name = "small_locks",
    hdrs = ["SmallLocks.h"],
    deps = [
        ":micro_spin_lock",
        ":pico_spin_lock",
        "//folly:micro_lock",
        "//folly:portability",
    ],
)

cpp_library(
    name = "wait_options",
    srcs = ["WaitOptions.cpp"],
    hdrs = ["WaitOptions.h"],
    deps = [
        "//folly:c_portability",
        "//folly:portability",
    ],
)

cpp_library(
    name = "delayed_init",
    hdrs = ["DelayedInit.h"],
    deps = [
        ":call_once",
        "//folly/lang:safe_assert",
    ],
)

cpp_library(
    name = "throttled_lifo_sem",
    hdrs = [
        "ThrottledLifoSem.h",
    ],
    deps = [
        ":distributed_mutex",
        ":saturating_semaphore",
        ":wait_options",
        "//folly:glog",
        "//folly:intrusive_list",
        "//folly:optional",
        "//folly/lang:align",
        "//folly/synchronization/detail:spin",
    ],
)

cpp_library(
    name = "flat_combining",
    hdrs = ["FlatCombining.h"],
    deps = [
        "//folly:function",
        "//folly:indexed_mem_pool",
        "//folly:portability",
        "//folly/concurrency:cache_locality",
        "//folly/synchronization:saturating_semaphore",
        "//folly/system:thread_name",
    ],
)

cpp_library(
    name = "event_count",
    hdrs = ["EventCount.h"],
    deps = [
        "//folly:likely",
        "//folly/detail:futex",
        "//folly/lang:bits",
        "//folly/portability:sys_time",
        "//folly/portability:unistd",
        "@glog",
    ],
)
